﻿<%@ WebHandler Language="C#" Class="HandlerContent" %>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.SessionState;
using BLL;
using Entity;
using PaymentBLL;
using HighLowGameBLL;

public class HandlerContent : IHttpHandler, IReadOnlySessionState
{

    public void ProcessRequest(HttpContext context)
    {
        string type = context.Request.QueryString["t"] ?? string.Empty;

        switch (type)
        {

            case "helpGetList":
                helpGetList(context);
                break;
            case "helpGetInfo":
                helpGetInfo(context);
                break;          
        }
    }


    public void helpGetList(HttpContext context)
    {
        var ctr = new CtrHiLoHelp();
        int gameId = Convert.ToInt32(context.Request.QueryString["gameId"] ?? "-1");
        int type = Convert.ToInt32(context.Request.QueryString["type"] ?? "-1");
        int status = Convert.ToInt32(context.Request.QueryString["status"] ?? "-1");
        string title = context.Request.QueryString["title"] ?? "";
        int currentPage = Convert.ToInt32(context.Request.QueryString["currentPage"] ?? "1");
        int pageSize = Convert.ToInt32(context.Request.QueryString["pageSize"] ?? "10");
        int? totalRecord = 0;
        var lst = ctr.SelectHiLoHelpBy(gameId,title,type,status,currentPage,pageSize,ref totalRecord);
        var strFunction = context.Request.UrlReferrer.AbsolutePath.Substring(context.Request.UrlReferrer.AbsolutePath.IndexOf("/") + 1).ToLower();
        var obj = new
        {
            Items = lst,
            TotalRecord = totalRecord ?? 0,
            Permission = CtrAdmin.GetPermission(strFunction)
        };
        string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
        context.Response.ContentType = "application/json";
        context.Response.Write(jsonString);
    }

    public void helpGetInfo(HttpContext context)
    {
        var ctr = new CtrHiLoHelp();
        int id = Convert.ToInt32(context.Request.QueryString["id"] ?? "-1");
        var info = ctr.SelectHiLoHelp(id);
        string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(info);
        context.Response.ContentType = "application/json";
        context.Response.Write(jsonString);
    }
    
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}